import { ApiResponse, ApiError, ErrorCode } from '@/types';

export const createApiResponse = <T>(
    success: boolean,
    message: string,
    data?: T
): ApiResponse<T> => ({
    success,
    message,
    ...(data !== undefined && { data }),
    timestamp: new Date(),
});

export const createSuccessResponse = <T>(
    message: string,
    data?: T
): ApiResponse<T> => createApiResponse(true, message, data);

export const createErrorResponse = (
    message: string,
    error?: string
): ApiResponse => ({
    success: false,
    message,
    ...(error !== undefined && { error }),
    timestamp: new Date(),
});

export const createApiError = (
    code: ErrorCode,
    message: string,
    details?: any
): ApiError => ({
    code,
    message,
    details,
    timestamp: new Date(),
});